package com.lzy.cloud.member.service.impl;

import com.lzy.cloud.member.dtos.MemberUserDto;
import com.lzy.cloud.member.entity.MemberUser;
import com.lzy.cloud.member.mapper.MemberUserMapperExt;
import com.lzy.cloud.member.service.MemberUserService;
import com.lzy.framework.core.utils.DozerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by WIN7 on 2018/5/30.
 */
@Service
public class MemberUserServiceImpl implements MemberUserService{

    @Autowired
    MemberUserMapperExt memberUserMapperExt;

    /**
     * 添加会员
     * @param memberUserDto
     * @return
     */
    @Override
    public Long addMemberUser(MemberUserDto memberUserDto) {
      MemberUser memberUser =DozerUtils.map(memberUserDto,MemberUser.class);
      return memberUserMapperExt.insertSelective(memberUser)>0?memberUser.getId():null;
    }

    @Override
    public Boolean updateMemberUser(MemberUserDto memberUserDto) {
        return memberUserMapperExt.updateByPrimaryKeySelective(DozerUtils.map(memberUserDto,MemberUser.class))>0;
    }

    @Override
    public MemberUserDto selectByMemberId(Long memberId) {
        return DozerUtils.map(memberUserMapperExt.selectByPrimaryKey(memberId),MemberUserDto.class);
    }

    @Override
    public List<MemberUserDto> selectList(MemberUserDto memberUserDto) {
        return memberUserMapperExt.selectList(memberUserDto);
    }

    @Override
    public Integer releaseTokenOccupancy(String deviceToken) {
        return memberUserMapperExt.releaseTokenOccupancy(deviceToken);
    }

}
